package lumis.service.wsrp.consumer.doui;

import java.util.Map;
import java.util.Properties;

import lumis.doui.source.TabularSource;
import lumis.portal.PortalException;
import lumis.portal.authentication.SessionConfig;
import lumis.service.wsrp.consumer.IPortletServiceManager;
import lumis.service.wsrp.consumer.PortletServiceManagerFactory;
import lumis.util.ITransaction;

/**
 * Data provider for cloned portlets properties.
 *
 * @version $Revision: 13092 $ $Date: 2011-05-28 18:19:06 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public class PropertiesDataProvider extends MapDataProvider
{
	@Override
	protected Map<?, ?> obtainMapData(
							SessionConfig sessionConfig,
							TabularSource<?> source,
							ITransaction transaction)
						throws PortalException
	{
		String producerEntityId = source.getDouiContext().getRequest().getServiceInstanceConfig().getId();
		String portletHandle = (String) source.getParameterValue("portletHandle");
		
		Properties properties = obtainProperties(producerEntityId, portletHandle);
		
		return properties;
	}
	
	/**
	 * Obtain the properties.
	 * @param producerEntityId	the producer entity id.
	 * @param portletHandle		the portlet handle.
	 * @return					an instance of Properties.
	 * @throws PortalException
	 */
	Properties obtainProperties(
					String producerEntityId,
					String portletHandle)
				throws PortalException
	{
		IPortletServiceManager serviceManager = PortletServiceManagerFactory.getPortletServiceManager(producerEntityId);
		
		Properties properties = serviceManager.getPortletProperties(portletHandle);
		return properties;
	}	
}